import java.util.ArrayList;
import java.util.List;
public class Composite {
    private final List<Composite> list;
    public void add(Composite c) {
        list.add(c);
    }

    final private String name;
    public Composite(String name) {
        this.list = new ArrayList<>();
        this.name = name;
    }

    //多态
    void printComposite() {
        System.out.println(name);
        for (Composite com : list) {
            com.printComposite();
        }
    }


    public static void main(String[] args) {
        Composite CEO = new Composite("CEO");
        Composite SubCeo1 = new Composite("SubCeo1");
        Composite SubCeo2 = new Composite("SubCeo2");
        Composite SubSubCeo1 = new Composite("SubsubCeo1");
        Composite SubSubCeo2 = new Composite("SubsubCeo2");
        Composite SubSubCeo3 = new Composite("SubsubCeo3");
        Composite SubSubCeo4 = new Composite("SubsubCeo4");
        SubCeo1.add(SubSubCeo1);
        SubCeo1.add(SubSubCeo2);
        SubCeo2.add(SubSubCeo3);
        SubCeo2.add(SubSubCeo4);
        CEO.add(SubCeo1);
        CEO.add(SubCeo2);
        CEO.printComposite();
        System.out.println("组合模式，客户端不关注当前对象在树中的位置，但需要提供同样的功能");
        SubCeo2.printComposite();
    }
}